//
//设备名称
//
<template>
  <div class="tenantMenu_main main_container">
    <div class="main_main">
      <div style="padding-right:20px" class="SearchBar_main main_main_search">
        <div style="padding-left:0" class="main_main_search_item">
          <div class="formItem_header">
            <div class="formItem_header_operate">
              <a class="formItem_header_operate_items" @click="add">
                <svg-icon icon-class="新增" />
                <div class="item_name">新增</div>
              </a>
            </div>
          </div>
        </div>
        <div class="main_main_search_item">
          <el-input v-model="pageData.searchValue" style="width:200px;margin-right:10px" placeholder="请输入" clearable @keyup.enter.native="getTypeList" @clear="getTypeList" />
          <el-button style="background:#387bfc;width:30px;" icon="el-icon-search" @click.stop="getTypeList" />
        </div>
      </div>
      <div ref="table_container" class="table_container">
        <el-table
          ref="table"
          :data="tableData"
          stripe
          border
          :height="tableHeight"

          :tree-props="{children: 'children', hasChildren: 'hasChildren'}"
          @row-click="rowClick"
        >
          <el-table-column prop="name" label="设备名称" />
          <el-table-column prop="code" label="设备编码" />
        </el-table>
      </div>
    </div>
    <div style="margin-top:40px;margin-right:10px" class="addtype-main_bottom">
      <pagination
        :total="total"
        :page.sync="pageData.pageNum"
        :limit.sync="pageData.pageSize"
        :selected-num="selectedNum"
        @pagination="getList"
      />
    </div>
  </div>
</template>

<script>
import { list } from '@/api/equipmentManage/baseInfo/equipmentInfo'
import AddOrUpdate from '../../baseInfo/equipmentInfo/addOrUpdate' // 新增或编辑页面
export default {
  name: 'Index',
  props: {
    layerid: {}
  },
  data() {
    return {
      pageId: '设备名称',
      pageData: {
        companyName: undefined,
        pageNum: 1,
        pageSize: 20,
        orderByColumn: 'updateTime',
        isAsc: 'desc',
        status: 1
      },
      seachDate: {
        pageNum: 1,
        pageSize: 20,
        orderByColumn: 'updateTime',
        searchValue: '',
        status: 1
      },
      total: 1, // 数据一共有多少条
      mainId: 'id',
      tableHeight: '0',
      tableData: []
    }
  },
  computed: {
    // 分页器
    selectedNum() {
      return this.$refs.table ? this.$refs.table.selection.length : 0
    }
  },
  watch: {
    'seachDate.searchValue'() {
      if (this.seachDate.searchValue == '' || this.seachDate.searchValue == null) {
        this.getList()
      }
    }
  },
  mounted() {
    this.getList()
    this.$nextTick(() => {
      this.tableHeight = this.$refs.table_container.offsetHeight
    })
  },
  methods: {
    getList() {
      list(this.pageData).then(res => {
        this.tableData = res.data
        this.total = res.total
      })
    },
    getTypeList() {
      list(this.seachDate).then(res => {
        this.tableData = res.data
      })
    },
    refresh() {
      this.pageData.pageNum = 1
      this.getList()
    },
    add() {
      this.$layer.iframe({// 弹框
        content: {
          content: AddOrUpdate, // 传递的组件对象
          parent: this, // 当前的vue对象
          data: {
          }// props
        },
        area: ['940px', '770px'],
        title: '新增设备信息', // 标题
        shadeClose: false // 点击遮罩是否关闭
      })
    },
    rowClick(row, column, event) { // 单击行选中
      this.$parent.addEquipmentName(row)
      this.$layer.close(this.layerid) // 关闭弹框
    }

  }
}
</script>

<style lang="less" scoped>
.formItem_header_operate_items{
  height: 30px;
  display: flex;justify-content: center;align-items: center;
  padding: 0px 10px;font-size: 16px;border-radius: 4px;
  color: rgba(56, 123, 252, 1);background-color: rgba(235, 242, 255, 1);
  .item_name{
    font-size: 14px;padding-left: 10px;
  }
}
.formItem_header_operate_items:hover{
  background-color: rgba(235, 242, 255, 0.5);
}
</style>
